<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <title>八维贷-借款端</title>
    <script src="https://unpkg.com/vue@2.6.14/dist/vue.min.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
</head>
<body>

<div id="app">
    <center>

        <hr>
        <img src="logo.png" width="60%">
        <hr>
        <div v-show="flag==1">
            已有八维贷账号，没有账号点击<a @click="flag=2">这里</a>

            <el-form style="margin-top: 30%">
                <el-form-item label="手机号">
                    <el-input v-model="user.phone" style="width: 75%"></el-input>
                </el-form-item>
                <el-form-item v-show="flag==1" label="密码" >
                    <el-input v-model="user.password" style="width: 75%"></el-input>
                </el-form-item >
                <el-button type="success" @click="bind">绑定</el-button>
            </el-form>


        </div>
        <div v-show="flag==2">
            没有八维贷账号，已有账号点击<a @click="flag=1">这里</a>
            <el-form style="margin-top: 30%">
                <el-form-item label="手机号">
                    <el-input v-model="user.phone" style="width: 75%"></el-input>
                </el-form-item>
                <el-form-item label="密码" >
                    <el-input v-model="user.password" style="width: 75%"></el-input>
                </el-form-item >
                <el-button type="success" @click="bind">注册</el-button>
            </el-form>



        </div>














        <div style="width: 100%;position: absolute;bottom: 0">
            <hr>
            www.bwyjs.com @
            云计算1810A
            <hr>
        </div>
    </center>
</div>
<script>
    new Vue({
        el:'#app',
        data() {
            return {
                flag: 1,
                user:{
                    phone:'',
                    password:'',
                    openid:''
                }
            };
        },
        methods: {
           bind(){
               axios.post("/bind/"+this.flag,this.user).then((res)=>{
                   if(res.data){
                       alert("账号关联成功！请重新登陆！")
                       location.href="index.html";
                   }else{
                       alert("账号关联失败！")
                   }
               })
           }
        },
        created(){
            var params = location.search;
            this.user.openid = params.substring(params.lastIndexOf("=")+1);
        }
    })
</script>
</body>
</html>